<?php
/**
 * User: @lose
 * Date: 2019-10-15
 * Time: 11:42
 */

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';

use Biz\model\ShopCategoryClassify as mShopCategoryClassify;

//$list = mShopCategoryClassify::select('*'); // 查出所有的数据

// 遍历每一条数据, 查询parend_id为当前id的，

 // 13 24
$sum = 0;
foreach ([1,2,3,4] as $deep) {

    // 父类状态为2或9的，子类要与父类统一。
    $list = mShopCategoryClassify::select('*', ['deep' => $deep]); // 父类所有数据

    foreach ($list as $info) {
        $item = mShopCategoryClassify::select('*', ['parent_id' => $info['id']]);
        $count = 0;
        foreach ($item as $value) {
            if($value['status'] == 9) {
                echo $value['id'] .'状态是9 '. '无需同步';
                continue;
            }
            if($info['status'] == 2) {
                $result = mShopCategoryClassify::update(['status' => 2], ['id' => $value['id']])->rowCount();
                $count = $count + $result;
            } else if ($info['status'] == 9) {
                $result = mShopCategoryClassify::update(['status' => 9], ['id' => $value['id']])->rowCount();
                $count = $count + $result;
            } else if ($info['status'] == 0) {
                $result = mShopCategoryClassify::update(['status' => 0], ['id' => $value['id']])->rowCount();
                $count = $count + $result;
            }
        }
        echo $deep .'级分类id '. $info['id'].' 修改数据量 ' . $count;

        $sum = $sum + $count;
    }
    echo PHP_EOL;
}
echo '修总量' .$sum;
